import * as types from '@/store/mutation-types';
import sendgetLoginRight from '@/request/Login';
import router from '@/router';
import { set } from '@/common/utils';
// import router from '@/router';

export default {

  async getLoginRight({ commit }, { name, password }) {
    commit(types.SHOW_LOADING);
    try {
      // eslint-disable-next-line
      const result = await sendgetLoginRight({ name, password }); // 发送请求
      console.log('getOrderStatis==>', result);
      set('loginName', result.role);

      if (result.role === 'admin') {
        set('operateShowStore', true);
        set('orderShowStore', true);
      }

      if (result.role === 'employee') {
        set('operateShowStore', false);
        set('orderShowStore', true);
      }

      if (result.role === 'visitor') {
        set('operateShowStore', false);
        set('orderShowStore', false);
      }

      //
    } catch (error) {
      commit(types.SHOW_ALERT, { message: error.message });// 原来log出起来的500，经过包装就是CustomError的新对象
    } finally {
      commit(types.HIDE_LOADING);
      router.push('admin/restaurant'); //* 跳转到 admin/restaurant
    }
  },

};
